App({
  globalData: {
    userInfo: null,
    ServiceUrl: 'https://chenjianfeng.xyz/phoneNum/',
    //  WXUrl: 'https://api.weixin.qq.com/sns/jscode2session',
    ValidateData: 'Epoint_WebSerivce_**##0601',
    appid: 'wx116fe7c5decc42ee',
    secret: 'e6d024fba6e1ec3a8bf841b68aff9ac4',
    OPEN_ID: '',
    city: '',
    SESSION_KEY: '',
    phoneNumber: '',
    nickname: '',
    uploadURL: 'https://up.qbox.me',
    domain: 'https://image.chenjianfeng.xyz/',
    region: 'ECN',
    uptokenURL: 'https://chenjianfeng.xyz/album/qiniufile/getUpToken',
    zanUrl: "https://image.chenjianfeng.xyz/zan.jpg",
    baiduMap: 'https://api.map.baidu.com/geocoder/v2/',
    baiduAK: 'Y1R5guY8Y2GNRdDpLz7SUeM3QgADAXec',
    headerUrl:'https://image.chenjianfeng.xyz/iconheader.png',
  },
  onLaunch: function () {
  },
  getUserInfo: function (cb) {
    var that = this
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
              that.globalData.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
    }
  },
  getCity: function (cb) {
    var that = this
    wx.getLocation({
      type: 'gcj02',
      success: function (res) {
        var locationParam = res.latitude + ',' + res.longitude + '1'
        wx.request({
          url: that.globalData.baiduMap,
          data: {
            ak: that.globalData.baiduAK,
            location: locationParam,
            output: 'json',
            pois: '1'
          },
          method: 'GET',
          success: function (res) {
            that.globalData.city = res.data.result.addressComponent.city.slice(0, -1)
            typeof cb == "function" && cb(res.data.result.addressComponent.city.slice(0, -1))
          },
          fail: function (res) {
            // 重新定位
            that.getCity();
          }
        })
      }
    })
  }
})